package com.lehecai.core.api.lottery;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.lottery.JczqDcSettingType;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 
 * @author qatang
 *
 */
public class JczqDcSetting extends AbstractApiResultBean implements Serializable{

	private static final long serialVersionUID = 1L;

	public static final String QUERY_TYPE = "type";
	public static final String QUERY_KEY = "key";
	public static final String QUERY_STATUS = "status";

	public static final String SET_TYPE = "type";
	public static final String SET_KEY = "key";
	public static final String SET_IMG_SRC = "img_src";
	public static final String SET_BET_AREA_SRC = "bet_area_src";
	public static final String SET_STATUS = "status";


	private JczqDcSettingType type;     //竞彩单场设置类型 1.按场次编号，2.按赛事
	private String key;                 //如果type为1表示赛程编号，如果type为2，表示赛事。
	private String imgSrc;              //背景图片url
	private String betAreaSrc;          //投注区碎片url
	private YesNoStatus status;         //1.开启，0.关闭

	
	public static JczqDcSetting convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		JczqDcSetting jczqDcSetting = new JczqDcSetting();
		jczqDcSetting.setType(JczqDcSettingType.getItem(getInt(object, SET_TYPE)));
		jczqDcSetting.setKey(getString(object, SET_KEY));
		jczqDcSetting.setImgSrc(getString(object, SET_IMG_SRC));
		jczqDcSetting.setBetAreaSrc(getString(object, SET_BET_AREA_SRC));
		jczqDcSetting.setStatus(YesNoStatus.getItem(getInt(object, SET_STATUS)));
		return jczqDcSetting;
	}

	@SuppressWarnings("unchecked")
	public static List<JczqDcSetting> convertFromJSONArray(JSONArray array) {
		logger.info(array.toString());
		if (array == null) {
			return null;
		}
		List<JczqDcSetting> list = new ArrayList<JczqDcSetting>();
		for (Iterator iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}
	
	public static JSONObject toJSON(JczqDcSetting dcRace) {
		JSONObject object = JSONObject.fromObject(dcRace);
		return object;
	}
	
	public static JSONArray toJSONArray(List<JczqDcSetting> dcRaces) {
		JSONArray ja = new JSONArray();
		JSONObject jsonObject = null;
		if(dcRaces != null && dcRaces.size() > 0){
			for(JczqDcSetting dcRace:dcRaces){
				jsonObject = JczqDcSetting.toJSON(dcRace);
				ja.add(jsonObject);
			}
		}
		return ja;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public JczqDcSettingType getType() {
		return type;
	}

	public void setType(JczqDcSettingType type) {
		this.type = type;
	}

	public String getBetAreaSrc() {
		return betAreaSrc;
	}

	public void setBetAreaSrc(String betAreaSrc) {
		this.betAreaSrc = betAreaSrc;
	}

	public YesNoStatus getStatus() {
		return status;
	}

	public void setStatus(YesNoStatus status) {
		this.status = status;
	}

	public String getImgSrc() {
		return imgSrc;
	}

	public void setImgSrc(String imgSrc) {
		this.imgSrc = imgSrc;
	}
}
